import { baseConfig } from '/@/api/backend/shop/common'
import { watch } from 'vue'
import { useAdminInfo } from '/@/stores/adminInfo'
import { useShopConfig } from '/@/stores/shop/shopConfig'
import { connectNotify } from '/@/components/shop/notify/wsNotify'
export const initializeShopConfig = () => {
    const adminInfo = useAdminInfo()
    const shopConfig = useShopConfig()

    watch(
        () => adminInfo.token,
        (newVal) => {
            if (newVal == '') {
                shopConfig.state.notify = false
            } else {
                baseConfig().then((res) => {
                    shopConfig.dataFill(res.data)
                    if (shopConfig.state.notify) {
                        connectNotify()
                    }
                })
            }
        },
        { immediate: true }
    )
}
